//
//  OnlineExamViewController.m
//  jinnengExam
//
//  Created by mac on 2020/11/13.
//  Copyright © 2020 jznrj. All rights reserved.
//

#import "EOnlineVideoViewController.h"

@interface EOnlineVideoViewController ()
@property(nonatomic,strong) JznWebView *jznWebView;
@property(nonatomic) int page;
@end

@implementation EOnlineVideoViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"在线直播";
    UINavigationBar * bar = self.navigationController.navigationBar;
        UIImage *bgImage = [ColorUtil navigationBarColor:[ColorUtil titleColor] BarSize:bar.frame alphe:1.0];
        [bar setBackgroundImage:bgImage forBarMetrics:UIBarMetricsDefault];
        [bar setTintColor:[UIColor whiteColor]];
        [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]}forState:UIControlStateNormal];
        [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil]];
    // Do any additional setup after loading the view.
    self.tabBarController.tabBar.frame = CGRectMake(0, 0, 0, 0);
    self.tabBarController.tabBar.hidden = YES;
    [self initView];
}

-(void) viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBar.hidden = NO;
}
-(void) initView{
   [self.view addSubview:self.jznWebView];
   [self.jznWebView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        if (@available(iOS 11.0, *)) {
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
        } else {
            make.top.bottom.equalTo(self.view);
        }
    }];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.jznWebView loadServerUrl:@"http://121.89.210.255:18089/jinneng_web/video.html"];
   // [self.jznWebView loadLocalFile:@"/ios_jinneng/onlineTrain" type:@"html"];

    
//    [self.jznWebView.scrollView.mj_header setBackgroundColor:[UIColor whiteColor]];
//    self.jznWebView.scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//        self.page = 1;
//        [self requestLearn:self.page];
//        
//    }];
//    
//    self.jznWebView.scrollView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
//        
//        [self requestLearn:++self.page];
//    }];
    [self registJSFunction];
}

-(void) registJSFunction{
//    [self.webViewBridge registerHandler:@"toTrainDetail" handler:^(id data, WVJBResponseCallback responseCallback) {
//         NSString *exam = data[@"exam"];
//        dispatch_async(dispatch_get_main_queue(), ^(){
//            EOnlineTrainDetailViewController *vc = [[EOnlineTrainDetailViewController alloc]init];
//            [vc setExamTrain:exam];
//            [self.navigationController pushViewController:vc animated:YES];
//        });
//     }];
}

- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{
        [self.jznWebView.scrollView.mj_header beginRefreshing];
}

//-(void) requestLearn:(int) page{
//    NSString *url = [NSString stringWithFormat:@"%@/professionalClass/findStudentClassList" ,[URLUtil hostName]];
//    NSDictionary *params = @{@"userId":[NSString stringWithFormat:@"%d",self.loginDto.userId],@"onlineClassType":@"1",@"learnStatus":@"1",@"pageNum":[NSString stringWithFormat:@"%d",page],@"pageSize":@"10"};
//    [JZNRequestUtil requestUrl:url requestParams:params success:^(DataResult *dataResult) {
//        if(dataResult.code == 0){
//            if (page == 1) {
//                NSString *clear = @"clear()";
//                //[self.jznWebView stringByEvaluatingJavaScriptFromString: clear];
//                [self.jznWebView evaluateJavaScript:clear completionHandler:^(id _Nullable data, NSError * _Nullable error) {
//                    
//                }];
//                [self.jznWebView.scrollView.mj_header endRefreshing];
//                [self.jznWebView.scrollView.mj_footer resetNoMoreData];
//            }
//            
//            NSString *clear = [NSString stringWithFormat:@"getExamList(%@)",[dataResult.data mj_JSONString]];
//            //[self.jznWebView stringByEvaluatingJavaScriptFromString: clear];
//            [self.jznWebView evaluateJavaScript:clear completionHandler:^(id _Nullable data, NSError * _Nullable error) {
//                
//            }];
//            NSArray *array = dataResult.data;
//            if([array count]<10){
//                
//                [self.jznWebView.scrollView.mj_footer endRefreshingWithNoMoreData];
//            }else{
//                
//                [self.jznWebView.scrollView.mj_footer endRefreshing];
//            }
//        }else {
//        }
//    } failure:^(NSError *error) {
//        
//    }];
//}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
